from PyQt4 import QtCore, QtGui
import sys

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


class Chargement(QtGui.QWidget):
     
    def __init__(self, parent=None):
        super(Chargement, self).__init__(parent)
 
        # bouton qui déclenche l'action
        self.bouton = QtGui.QPushButton(u"début", self)
        self.bouton.clicked.connect(self.action)
         
        # création du QProgressDialog
        self.prog = QtGui.QProgressDialog("En cours...", "Annuler", 0, 0, self)
        self.prog.setWindowTitle(u"Traitement")
        # branchement du bouton "annuler" à la méthode 'stopaction'
        self.prog.canceled.connect(self.stopaction)
         
    def action(self):
        self.prog.show()
 
    def stopaction(self):
        self.prog.reset()
